<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="true" title="处理申请" back-icon-color='#333333' height="50" :border-bottom="false">
		</u-navbar>
		<u-picker mode="time" v-model="time_boolen" :params="params" @confirm="submit"></u-picker>
		<u-select v-model="show" mode="single-column" :list="list" @confirm="confirm"></u-select>
		<u-mask :show="display">
			<view class="warp">
				<view class="rect" @tap.stop>
					<view class="tanchu">
						确认取消申请?
					</view>
					<view class="anniu">
						<view class="" @click="display=false">
							取消
						</view>
						<view class="" @click="retreatProgress">
							确定
						</view>
					</view>
				</view>
			</view>
		</u-mask>
		<view class="list">
			<view class="teacher">
				<text>教师名称</text>
				<u-input v-model="form.teacher_name" style="margin-left:200rpx; width: 200rpx;" :type="type"
					placeholder="单行输入" :border="border" input-align="right" />
			</view>
			<view class="position">
				<text>教师职位</text>
				<u-input v-model="form.teacher_post" style="margin-left:200rpx; width: 200rpx;" :type="type"
					placeholder="单行输入" :border="border" input-align="right" />
			</view>
			<view class="absence">
				<text>请假时间</text>
				<text>{{form.time}}</text>
				<image src="../../static/tupian105.png" mode="widthFix" @click="time_boolen=true"></image>
			</view>
			<view class="leave_time">
				<text>请假时长</text>
				<text>{{form.time_length}}</text>
				<text @click="show=true"></text>
			</view>
			<view class="leave_reason">
				<text>请假原因</text>
			</view>
			<view class=""
				style="width:94%; height:15rpx; margin-left:3%; background:#F2F2F2; border-top-left-radius:12rpx; border-top-right-radius:12rpx;">

			</view>
			<textarea value="" v-model="form.reason" placeholder="单行输入"
				style="width:94%; height:180rpx; margin-left:3%; background:#F2F2F2; text-indent:1em; border-bottom-left-radius:12rpx; border-bottom-right-radius:12rpx;" />
			<view class="" style="width:100%; height:84rpx;">
			</view>
		</view>
		<view class="confirm">
			<view class="cancel" @click="display=true">
				{{cancel}}
			</view>
			<view class="verify" @click="updateProgress">
				{{verify}}
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../request.js'
	export default {
		data() {
			return {
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				time_boolen: false,
				input_content: '',
				verify: '确认修改',
				cancel: '取消申请',
				display: false,
				content: '',
				border: false,
				show: false,
				type: 'text',
				delivery_obj: {},
				form: {
					progress_id: '',
					progress_type: '',
					teacher_name: '',
					teacher_post: '',
					time_length: '',
					reason: '',
					time: '',
				},
				list: [{
						value: '1',
						label: '半天'
					},
					{
						value: '2',
						label: '一天'
					}
				],
			}
		},
		onLoad(option) {
			if (option.obj) {
				console.log('进来了吗')
				this.delivery_obj = JSON.parse(decodeURIComponent(option.obj));
				this.form.progress_id = this.delivery_obj.progress_id;
				this.form.progress_type = this.delivery_obj.progress_type;
				this.form.teacher_name = this.delivery_obj.teacher_name;
				this.form.teacher_post = this.delivery_obj.teacher_post;
				this.form.time = this.delivery_obj.time;
				this.form.time_length = this.delivery_obj.time_length;
				this.form.reason = this.delivery_obj.reason;
			}
		},
		methods: {
			confirm(e) {
				console.log(e[0].label);
				this.form.time_length = e[0].label;
			},
			submit(e) { //对时间的格式进行处理
				this.form.time = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}:${e.second}`;
			},
			updateProgress() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/progress/updateProgress',
					method: 'post',
					data: {
						...this.form,
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							_this.$toLink('../approval_flow/approval_flow', {})
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			retreatProgress() {
				this.display = false;
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				request({
					url: base_url + 'teacher/progress/retreatProgress',
					method: 'post',
					data: {
						progress_id: this.form.progress_id,
						retreat_reason: this.form.reason
					},
					success(res) {
						if (res.statusCode == 200) {
							console.log(res.data.data);
							_this.$toLink('../approval_flow/approval_flow', {})
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},

		}
	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		overflow: hidden;
		height: 100vh;
		background: #F2F2F2;

		.warp {
			display: flex;
			align-items: flex-start;
			justify-content: center;
			height: 100%;

			.rect {
				margin-top: 450rpx;
				border-radius: 10rpx;
				width: 480rpx;
				height: 250rpx;
				background-color: #fff;

				.tanchu {
					width: 100%;
					height: 150rpx;
					font-size: 33rpx;
					color: #3E3E3E;
					text-align: center;
					line-height: 150rpx;
				}

				.anniu {
					width: 100%;
					height: 100rpx;
					display: flex;
					justify-content: space-around;
					align-items: center;

					view {
						border-radius: 30rpx;
						width: 150rpx;
						height: 60rpx;
						text-align: center;
						line-height: 60rpx;
						font-size: 26rpx;

						&:nth-child(1) {
							color: #2C78FE;
							margin-left: 15rpx;
							border: 1px solid #2C78FE;
							background: #fff;

						}

						&:nth-child(2) {
							color: #fff;
							margin-right: 15rpx;
							background: linear-gradient(to right, #2C78FE, #32B0FF);
						}


					}
				}
			}
		}

		.list {
			width: 710rpx;
			margin-left: 20rpx;
			margin-top: 20rpx;
			background: #fff;
			border-radius: 12rpx;
			overflow: hidden;

			.teacher {
				width: 94%;
				margin-left: 3%;
				height: 84rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}

					&:nth-child(2) {
						color: #333333;
						margin-left: 420rpx;
					}
				}

			}

			.position {
				width: 94%;
				margin-left: 3%;
				height: 84rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}
				}
			}

			.absence {
				width: 94%;
				margin-left: 3%;
				height: 84rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 150rpx;
					}

					&:nth-child(2) {
						color: #333333;
						text-align: right;
						width: 440rpx;
					}
				}

				image {
					width: 40rpx;
					margin-left: 25rpx;
				}
			}

			.leave_time {
				width: 94%;
				display: flex;
				margin-left: 3%;
				align-items: center;
				justify-content: flex-start;
				height: 84rpx;
				border-bottom: 1px solid #F2F2F2;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 200rpx;
					}

					&:nth-child(2) {
						color: #333333;
						margin-left: 330rpx;
						width: 80rpx;
					}

					&:nth-child(3) {
						width: 0rpx;
						margin-top: 20rpx;
						height: 0rpx;
						border-width: 18rpx 18rpx 18rpx 18rpx;
						border-color: #ccc transparent transparent transparent;
						border-style: solid;
					}
				}
			}

			.leave_reason {
				width: 94%;
				display: flex;
				margin-left: 3%;
				align-items: center;
				justify-content: flex-start;
				height: 84rpx;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 200rpx;
					}
				}
			}

		}

		.confirm {
			width: 100%;
			height: 450rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;

			.verify {
				width: 200rpx;
				height: 60rpx;
				border-radius: 50rpx;
				text-align: center;
				line-height: 60rpx;
				background: linear-gradient(to right, #2C78FE, #32B0FF);
				color: #fff;
				font-size: 30rpx;
			}

			.cancel {
				width: 200rpx;
				height: 60rpx;
				border-radius: 50rpx;
				text-align: center;
				line-height: 60rpx;
				background: #fff;
				color: #666666;
				font-size: 30rpx;
			}
		}
	}
</style>
